package com.weixing.mall.provider.controller.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.core.utils.RequestUtil;
import com.weixing.mall.provider.api.model.vo.RoleVo;
import com.weixing.mall.provider.model.domain.User;
import com.weixing.mall.provider.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@RequestMapping("agentWithdraw")
@Api(value = "CMS报表Api",tags = "报表菜单模块")
public class ReportCmsController {
    @Autowired
    private IUserService userService;

    @ApiOperation(value = "报表菜单初始化")
    @GetMapping("/initMenu")
    public Result MenuList(@SysInfo SysAuth auth) {
        List<User> userList = Lists.newArrayList();
        List<RoleVo> list = userService.getRoleById(auth.getUid());
        int flag = 0;
        for (RoleVo vo : list) {
            if (vo.getRoleName().contains("客服主管")) {//如果为客服主管，则返回第一层菜单返回所有客服人员信息
                flag = 1;
            }
        }
        User user = userService.findByLoginName(RequestUtil.getCurrentUserName());//获取登录人员信息
        if (flag == 0) {//客服返回客服本人信息
            userList.add(user);
        } else {
            userList = userService.list(new QueryWrapper<User>().eq("dept_id", user.getDeptId()));
        }
        return ResultUtil.success(userList);
    }
}
